When managing complex data structures, choosing the right pattern can significantly impact the efficiency and effectiveness of your app.
stdout
warning prints to the console.MAP
comprised of multiple, hierarchical levels.
For example, consider a people
collection that contains documents with the following schema:
cars
where each car can be arbitrarily large:
MAP
objects in a single document may result in slow sync performance. So, rather than using a single document to encode a large dataset, use a series of smaller documents, which are inexpensive in terms of storage and processing resources.
Ditto considers collections inexpensive in terms of storage and processing resources. Ditto uses a combination of the collection name and the document ID to sync and query documents, and collections serve as an index for a set of related documents. You can use this index to establish foreign-key relationships between them by referencing the document ID. For more information, see Relationships.
_id
is immutable, only use the flat model in situations where you have static identifiers within your foreign-key relationship.people
collection and a cars
collection. In the following example, each car has an owner — represented by the _id.ownerId
field — which relates to the person’s document ID. In the people
collection:
cars
collection:
Criteria | Model |
---|---|
You often retrieve or update pairs of embedded items together. | Embedded MAP |
You frequently access or modify only certain parts of the data. | Flat |
ATTACHMENT
data type. For more information, see ATTACHMENT.
Criteria | Model |
---|---|
It is unlikely for the embedded MAP to potentially impact overall system performance. | Embedded |
You expect that the embedded MAP will become more complex and larger over time, making it difficult to manage and potentially causing system performance to degrade. | Flat |
Criteria | Model |
---|---|
Your end users will likely modify the same data items stored locally on their respective devices while internet is unavailable. | Embedded |
It is unlikely that your end users will simultaneously modify the same data items stored locally on their respective devices when the internet is unavailable. | Flat |
Criteria | Model |
---|---|
Your embedded MAP are relatively simple in structure and do not require maintainability over time. | Embedded |
Multiple embedded MAP structures are becoming deeply nested; as in there are embedded structures representing three or more levels in a hierarchy resulting in a necessity for better organization. | Flat |